{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-page">
	<h3 class="pb-2">离职申请</h3>
	{if condition="$id eq 0"}
	<table class="layui-table layui-table-form">
		<tr>
			<td class="layui-td-gray">离职员工<font>*</font></td>
			<td>				
				<input type="text" name="name" placeholder="请选择离职员工" lay-reqText="请选择离职员工" lay-verify="required" autocomplete="off" class="layui-input picker" readonly>
				<input type="hidden" name="uid" value="0" autocomplete="off">
				<input type="hidden" name="did" value="0" autocomplete="off">
			</td>
			<td class="layui-td-gray">所在部门</td>
			<td><input type="text" name="department" autocomplete="off" class="layui-input" readonly></td>
		</tr>
		<tr>
			<td class="layui-td-gray">离职日期<font>*</font></td>
			<td><input type="text" name="quit_time" lay-verify="required" autocomplete="off" placeholder="请选择离职日期" lay-reqText="请选择离职日期" readonly class="layui-input tool-time"></td>
			<td class="layui-td-gray-2">上级领导<font>*</font></td>
			<td>
				<input type="text" name="lead_admin_name" autocomplete="off" lay-verify="required" placeholder="请选择上级领导" lay-reqText="请选择上级领导" readonly class="layui-input picker-admin">
				<input type="hidden" name="lead_admin_id" autocomplete="off" value="0">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray-2">资料接受人<font>*</font></td>
			<td>				
				<input type="text" name="connect_name" autocomplete="off" lay-verify="required" placeholder="请选择资料接受人" lay-reqText="请选择资料接受人" readonly class="layui-input picker-admin">
				<input type="hidden" name="connect_id" class="layui-input">
			</td>
			<td class="layui-td-gray-2">参与交接人员<font>*</font></td>
			<td>				
				<input type="text" name="connect_names" autocomplete="off" lay-verify="required" placeholder="请选择参与交接人员" lay-reqText="请选择参与交接人员" readonly class="layui-input picker-admin" data-type="2">
				<input type="hidden" name="connect_uids" class="layui-input">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">离职原因<font>*</font></td>
			<td colspan="3">				
				<textarea name="remark" lay-verify="required" placeholder="请输入离职原因" lay-reqText="请输入离职原因" class="layui-textarea"></textarea>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">附件 <button type="button" class="layui-btn layui-btn-xs" id="uploadBtn"><i class="layui-icon"></i></button></td>
			<td colspan="3">
				<div class="layui-row" id="uploadBox">
					<input data-type="file" type="hidden" name="file_ids" value="">
				</div>
			</td>
		</tr>
	</table>
	{else/}
	<table class="layui-table layui-table-form">
		<tr>
			<td class="layui-td-gray">离职员工</td>
			<td>{$detail.name}</td>
			<td class="layui-td-gray">所在部门</td>
			<td>{$detail.department}</td>
		</tr>
		<tr>
			<td class="layui-td-gray">离职日期<font>*</font></td>
			<td><input type="text" name="quit_time" value="{$detail.quit_time}" lay-verify="required" autocomplete="off" placeholder="请选择离职日期" lay-reqText="请选择离职日期" readonly class="layui-input tool-time">
			</td>
			<td class="layui-td-gray-2">上级领导<font>*</font></td>
			<td>
			<input type="text" name="lead_admin_name" autocomplete="off" value="{$detail.lead_admin_name}" lay-verify="required" placeholder="请选择上级领导" lay-reqText="请选择上级领导" readonly class="layui-input picker-admin">
			<input type="hidden" name="lead_admin_id" autocomplete="off" value="{$detail.lead_admin_id}">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray-2">资料接受人<font>*</font></td>
			<td>				
				<input type="text" name="connect_name" autocomplete="off" lay-verify="required" placeholder="请选择资料接受人" lay-reqText="请选择资料接受人" readonly class="layui-input picker-admin" value="{$detail.connect_name}">
				<input type="hidden" name="connect_id" class="layui-input" value="{$detail.connect_id}">
			</td>
			<td class="layui-td-gray-2">参与交接人员<font>*</font></td>
			<td>				
				<input type="text" name="connect_names" autocomplete="off" lay-verify="required" placeholder="请选择参与交接人员" lay-reqText="请选择参与交接人员" readonly class="layui-input picker-admin" data-type="2" value="{$detail.connect_names}">
				<input type="hidden" name="connect_uids" class="layui-input" value="{$detail.connect_uids}">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">离职原因<font>*</font></td>
			<td colspan="3">				
				<textarea name="remark" lay-verify="required" placeholder="请输入离职原因" lay-reqText="请输入离职原因" class="layui-textarea">{$detail.remark}</textarea>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">附件 <button type="button" class="layui-btn layui-btn-xs" id="uploadBtn"><i class="layui-icon"></i></button></td>
			<td colspan="3">
				<div class="layui-row" id="uploadBox">
					<input data-type="file" type="hidden" name="file_ids" value="{$detail.file_ids|default=''}">
					{notempty name="$detail.file_ids"}
					{volist name="$detail.file_array" id="vo"}
					<div class="layui-col-md4">{:file_card($vo)}</div>
					{/volist}
					{/notempty}
				</div>
			</td>
		</tr>
	</table>
	{/if}
	<div id="checkBox" data-status="{$detail.check_status|default=0}" data-id="{$detail.id|default=0}" data-checkflowid="{$detail.check_flow_id|default=0}" class="pt-3"></div>
	<div class="pt-4">
		<input type="hidden" name="id" value="{$id}" />
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool','uploadPlus','oaCheck','oaPicker'];
	function gouguInit() {
		var form = layui.form,tool=layui.tool,uploadPlus=layui.uploadPlus,oaCheck=layui.oaCheck,oaPicker=layui.oaPicker;
		oaCheck.init({
			check_name:'personal_quit',
			check_btn:0
		});	
		var fileUp = new uploadPlus();

		$('body').on('click','[name="department"]',function(){
			var val=$(this).val();
			if(val==''){
				layer.msg('请选择离职员工');
			}			
		});		
		
		//选择员工弹窗	
		$('body').on('click','.picker',function () {
			let that = $(this);
			let ids=that.next().val()+'',names = that.val()+'';
			oaPicker.employeeInit({
				ids:ids,
				names:names,
				type:1,//1是单选，2是多选
				callback:function(data){
					//这里是选择后的回调方法，可以根据具体需求自定义写哦
					let select_id=[],select_name=[],select_did=[],select_department=[];
					for(var a=0; a<data.length;a++){
						select_id.push(data[a].id);
						select_name.push(data[a].name);
						select_did.push(data[a].did);
						select_department.push(data[a].department);
					}
					that.val(select_name.join(','));
					that.next().val(select_id.join(','));
					$('[name="uid"]').val(select_id.join(','));
					$('[name="name"]').val(select_name.join(','));
					$('[name="did"]').val(select_did.join(','));
					$('[name="department"]').val(select_department.join(','));
				}
			});
		}); 

		//监听提交
		form.on('submit(webform)', function (data) {
			if(data.field.uid==data.field.lead_admin_id){
				layer.msg('离职员工和上级领导不能是同一个人');
				return false;
			}
			if(data.field.uid==data.field.connect_id){
				layer.msg('离职员工和资料接受人不能是同一个人');
				return false;
			}
			
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					let checkCallback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							tool.sideClose(1000);				
						}
					}
					data.field.check_name = 'personal_quit';
					data.field.action_id = e.data.return_id;
					oaCheck.submit(data.field,checkCallback);
				}
			}
			let clickbtn = $(this);
			tool.post("/user/personal/leave_add", data.field, callback,clickbtn);
			return false;
		});	
	}

</script>
{/block}
<!-- /脚本 -->